'use strict';
//配送订单详情
import React,{Component} from 'react';
import Header from '../../common/header';
import * as URLconstant from '../../constant/URLconstant'
import Util from '../../common/util';
import {
    View,
    Text,
    TouchableOpacity,
    Image,
    StyleSheet,
    ScrollView,
} from 'react-native';
export default class orderDetail extends Component{
    // 构造
      constructor(props) {
        super(props);
        // 初始状态
        this.state = {
            orderData:null
        };
      }

    componentDidMount() {
        this.getOrderDetail()
    }

      getOrderDetail(){
          let url = URLconstant.GET_ORDER_DETAIL
          let datakey=[]
          datakey['user_id']=this.props.user_id
          datakey['order_id'] = this.props.order_id;
          Util.get(url,datakey,this.getOrderSuc.bind(this),this.errorCallback.bind(this))
      }

    getOrderSuc(datas){
        if(datas.status==0){
            this.setState({
                orderData:datas.data
            })
        }
    }

    errorCallback(err){

    }


    backOrderStatus(status){
          let orderStatus =''
          switch (parseInt(status)){
              case 11:
                  orderStatus = '待付款';
                  break;
              case 20:
                  orderStatus = '待发货';
                  break;
              case 30:
                  orderStatus = '已发货';
                  break;
              case 40:
                  orderStatus = '已完成';
                  break;
              case 0:
                  orderStatus = '已取消';
                  break;
              case 1:
                  orderStatus = '待成团';
                  break;
              case 2:
                  orderStatus = '拼团成功';
                  break;
              case 3:
                  orderStatus = '拼团失败';
                  break;
              default:
                  orderStatus = '退换货';
          }
          return orderStatus
    }

    backDeliveryStatus(status){
          let deliveryStatus = ''
        switch (parseInt(status)){
            case 5:
                deliveryStatus='待配货'
                break
            case 1:
                deliveryStatus='待配送'
                break
            case 3:
                deliveryStatus='配送中'
                break
            case 4:
                deliveryStatus='送货成功'
                break
            default:
                deliveryStatus='待处理'
        }
        return deliveryStatus
    }

      render(){
          let orderData = this.state.orderData
          return(
              <View style={{flex:1,backgroundColor:"#f0f0f0"}}>
                  <Header navigator={this.props.navigator} initObj={{ title: '订单详情',id:2}}/>
                  {
                      orderData==null?
                          <View style={{flex:1}}>
                              {Util.loading()}
                          </View>:
                          <ScrollView style={{flex:1,padding:10}}>
                              <View style={styles.info_box}>
                                <View style={styles.order_top}>
                                    <Text style={{fontSize:16,color:"#000"}}>订单详情</Text>
                                </View>
                                  <View style={styles.order_view}>
                                      <View style={[styles.txt_view,styles.no_border]}>
                                          <Text style={{fontSize:14,color:"#666"}}>订单号:{orderData.order_sn}</Text>
                                      </View>
                                      <View style={styles.txt_view}>
                                          <Text style={{fontSize:14,color:"#666"}}>下单时间:{orderData.add_time}</Text>
                                      </View>
                                      <View style={styles.txt_view}>
                                          <Text style={{fontSize:14,color:"#666"}}>店铺名称:{orderData.seller_name}</Text>
                                      </View>
                                      <View style={styles.txt_view}>
                                          <Text style={{fontSize:14,color:"#666"}}>订单状态:{this.backOrderStatus(orderData.status)}</Text>
                                      </View>
                                      <View style={styles.txt_view}>
                                          <Text style={{fontSize:14,color:"#666"}}>支付方式:{orderData.payment_name}</Text>
                                      </View>
                                  </View>
                              </View>
                              <View style={styles.info_box}>
                                  <View style={styles.order_top}>
                                      <Text style={{fontSize:16,color:"#000"}}>收货人及物流信息</Text>
                                  </View>
                                  <View style={styles.order_view}>
                                      <View style={[styles.txt_view,styles.no_border]}>
                                          <Text style={{fontSize:14,color:"#666"}}>收货人姓名:{orderData.buyer_name}</Text>
                                      </View>
                                      <View style={styles.txt_view}>
                                          <Text style={{fontSize:14,color:"#666"}}>手机号码:{orderData.phone_mob}</Text>
                                      </View>
                                      <View style={styles.txt_view}>
                                          <Text style={{fontSize:14,color:"#666"}}>收货地址:{orderData.region_name}{orderData.address}</Text>
                                      </View>
                                  </View>
                              </View>
                              {
                                  orderData.if_delivery==2||orderData.if_delivery==1?
                                      <View style={styles.info_box}>
                                          <View style={styles.order_top}>
                                              <Text style={{fontSize:16,color:"#000"}}>极速配送信息</Text>
                                          </View>
                                          <View style={styles.order_view}>
                                              <View style={[styles.txt_view,styles.no_border]}>
                                                  <Text style={{fontSize:14,color:"#666"}}>配送门店:{orderData.shop_name}</Text>
                                              </View>
                                              <View style={[styles.txt_view,styles.no_border]}>
                                                  <Text style={{fontSize:14,color:"#666"}}>配货店员:{orderData.shop_member}</Text>
                                              </View>
                                              <View style={[styles.txt_view,styles.no_border]}>
                                                  <Text style={{fontSize:14,color:"#666"}}>配送人员:{orderData.delivery_man}</Text>
                                              </View>
                                              <View style={[styles.txt_view,styles.no_border]}>
                                                  <Text style={{fontSize:14,color:"#666"}}>配送状态:{this.backDeliveryStatus(orderData.delivery_status)}</Text>
                                              </View>
                                          </View>
                                      </View>:null
                              }
                              <View style={styles.info_box}>
                                  <View style={styles.order_top}>
                                      <Text style={{fontSize:16,color:"#000"}}>订单商品</Text>
                                  </View>
                                  <View style={styles.order_view}>
                                      {
                                          orderData.order_goods.map((item,index)=>{
                                              return(
                                                  <View key={index} style={styles.goods_item}>
                                                      <Image
                                                          source={{uri:item.goods_image}}
                                                          style={{width:85,height:85,}}
                                                          resizeMode={'cover'}
                                                      />
                                                      <View style={styles.goods_item_right}>
                                                          <Text style={{fontSize:14,color:"#000"}}>{item.goods_name}</Text>
                                                          <Text style={{fontSize:14,color:"#f00"}}>价格:{item.price}</Text>
                                                          <Text style={{fontSize:12,color:"#f00"}}>购买数量:{item.quantity}</Text>
                                                      </View>
                                                  </View>
                                              )
                                          })
                                      }
                                  </View>
                              </View>
                              <View style={styles.info_box}>
                                  <View style={styles.order_top}>
                                      <Text style={{fontSize:16,color:"#000"}}>订单金额</Text>
                                  </View>
                                  <View style={styles.order_view}>
                                      <View style={[styles.txt_view,styles.no_border]}>
                                          <Text style={{fontSize:14,color:"#666"}}>商品总价:</Text>
                                          <Text style={{fontSize:14,color:"#f00"}}>{orderData.goods_amount}</Text>
                                      </View>
                                      <View style={[styles.txt_view,styles.no_border]}>
                                          <Text style={{fontSize:14,color:"#666"}}>配送费用:</Text>
                                          <Text style={{fontSize:14,color:"#f00"}}>{orderData.shipping_fee}</Text>
                                      </View>
                                      <View style={[styles.txt_view,styles.no_border]}>
                                          <Text style={{fontSize:14,color:"#666"}}>订单总价:</Text>
                                          <Text style={{fontSize:14,color:"#f00"}}>{orderData.order_amount}</Text>
                                      </View>
                                  </View>
                              </View>
                          </ScrollView>
                  }
              </View>
          )
      }
}
var styles = StyleSheet.create({
    info_box:{
        borderWidth:1,
        borderColor:"#ddd",
        backgroundColor:"#fff",
        marginBottom:10
    },
    order_top:{
        height:40,
        justifyContent:'center',
        paddingHorizontal:10,
        borderBottomWidth:1,
        borderBottomColor:"#ddd"
    },
    order_view:{
        paddingHorizontal:10,
        paddingVertical:5
    },
    txt_view:{
        paddingVertical:5,
        flexDirection:'row',
        alignItems:'center',
        borderTopWidth:1,
        borderTopColor:"#e0e0e0",
    },
    no_border:{
        borderTopWidth:0
    },
    goods_item:{
      flexDirection:'row',
    },
    goods_item_right:{
        justifyContent:'space-between',
        paddingLeft:10
    }
})